package flc.ast.activity;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.blankj.utilcode.util.ToastUtils;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.bean.StarsBean;
import flc.ast.databinding.ActivityPairResultBinding;
import stark.common.apis.ApiManager;
import stark.common.apis.base.ConstPairBean;
import stark.common.base.IReqRetCallback;
import stark.common.basic.event.EventStatProxy;

public class PairResultActivity extends BaseAc<ActivityPairResultBinding> {

    public static StarsBean yourStar, herStar;

    @Override
    protected int onCreate() {
        return R.layout.activity_pair_result;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);

        mDataBinding.ivPairResultBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.ivYourStarSign.setImageResource(yourStar.getImg());
        mDataBinding.ivHerStarSign.setImageResource(herStar.getImg());
    }

    @Override
    protected void initData() {
        //获取匹配信息
        ApiManager.constApi().getConstPairInfo(this, yourStar.getName(), herStar.getName(), new IReqRetCallback<ConstPairBean>() {
            @Override
            public void onResult(boolean success, String msg, @Nullable ConstPairBean result) {
                if (success) {
                    setPairData(result);
                } else {
                    ToastUtils.showShort(getString(R.string.is_limit));
                }
            }
        });
    }

    //设置匹配信息
    private void setPairData(ConstPairBean result) {
        mDataBinding.tvPairResult.setText("“" + result.getJieguo() + "”");
        mDataBinding.tvPairPercent.setText(result.getZhishu() + getString(R.string.unit_percent));
        mDataBinding.sbLqxy.setProgress(Integer.parseInt(result.getXiangyue()));
        mDataBinding.sbTcdj.setProgress(Integer.parseInt(result.getTcdj()));
        mDataBinding.tvPairResultLqxy.setText(result.getXiangyue() + getString(R.string.unit_percent));
        mDataBinding.tvPairResultTcdj.setText(result.getTcdj() + getString(R.string.unit_percent));
        mDataBinding.tvPairResultLajy.setText(result.getLianai());
        mDataBinding.tvPairResultZysx.setText(result.getZhuyi());
    }

}